/**
 * 
 */
package view;

import java.util.Observable;
import java.util.Observer;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import org.jvnet.substance.skin.SubstanceNebulaLookAndFeel;

import model.Venda;

import controller.ProdutoServicos;
import controller.VendaServicos;

/**
 * @author Eve
 * 
 */
public class TelaVendedorGUI implements Observer {

	private VendaServicos vendaServicos;
	private ProdutoServicos pServicos = new ProdutoServicos();
	private VendedorGUI vendedorGUI;
	private Venda venda;

	public TelaVendedorGUI(VendaServicos vendaServicos2, Venda venda) {
		this.vendaServicos = vendaServicos2;
		this.venda = venda;
		venda.addObserver(this);
		criarJanela();
	}

	private void criarJanela() {
		try {
			UIManager.setLookAndFeel(new SubstanceNebulaLookAndFeel());

			JFrame.setDefaultLookAndFeelDecorated(true);
			JDialog.setDefaultLookAndFeelDecorated(true);
			Runnable threadGUI = new Runnable() {
				public void run() {
					vendedorGUI = new VendedorGUI(vendaServicos, venda,
							pServicos.listarProdutos());
				}
			};

			javax.swing.SwingUtilities.invokeLater(threadGUI);

		} catch (UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	@Override
	public void update(Observable o, Object arg) {
		if (o instanceof Venda) {
			this.vendedorGUI.atualizaTela(pServicos.listarProdutos());
		}
	}

}
